package com.xlh.dokka.svc.core.novnc;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @author cheer
 */
@Slf4j
public abstract class AbstractNovncConnector implements NovncConnector {

    protected String prefix;

    private static final String NOVNC_URL = "/vnc_auto.html?path=websockify/?token=%s";

    @Override
    public String getNovnc(Long dokkaId, String vnc) {
        if (dokkaId == null || StringUtils.isBlank(vnc)) {
            return null;
        }

        if (writeToken(dokkaId, vnc)) {
            return String.format(NOVNC_URL, prefix + dokkaId);
        }
        return null;
    }

    protected abstract Boolean writeToken(Long dokkaId, String vncAddress);

}
